<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>试题管理</title>
    <link rel="stylesheet" href="/css/layui.css">
</head>
<body>
<!-- 表格 -->
<table class="layui-hide" id="testDetail1" lay-filter="testDetailInfo"></table>

<!-- 头部工具栏 -->
<script type="text/html" id="testDetailToolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i>添加试题信息</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="deleteAll" ><i class="layui-icon layui-icon-delete"></i>批量删除</button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    </div>
</script>

<!-- 行工具栏 -->
<script type="text/html" id="testDetailBar">
    <a class="layui-btn layui-btn-xs" lay-event="update"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>

<!-- 弹出修改界面 -->
<form class="layui-form" id="testDetail2" style="display: none"  lay-filter="testDetail">

    <div class="layui-form-item" style="display: none">
        <label class="layui-form-label">编号</label>
        <div class="layui-input-inline">
            <input type="text" name="id" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">试卷编号</label>
        <div class="layui-input-inline">
            <input type="text" name="testId" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">测试时间</label>
        <div class="layui-input-inline">
            <input type="text" name="testTime" lay-verify="required" lay-reqText="请输入测试时间" placeholder="请输入测试时间" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">题号</label>
        <div class="layui-input-inline">
            <input type="text" name="tittleNum" lay-verify="required" lay-reqText="请输入题号" placeholder="请输入题号" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">题目类别</label>
        <div class="layui-input-inline">
            <input type="text" name="tittleType" lay-verify="required" lay-reqText="" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">考点</label>
        <div class="layui-input-inline">
            <input type="text" name="knowledge" lay-verify="required" lay-reqText="" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">知识</label>
        <div class="layui-input-inline">
            <input type="text" name="konwdlage" lay-verify="required" lay-reqText="" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">最低分</label>
        <div class="layui-input-inline">
            <input type="text" name="lowestScore" lay-verify="required" lay-reqText="" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">最高分</label>
        <div class="layui-input-inline">
            <input type="text" name="highestScore" lay-verify="required" lay-reqText="" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">班级平均分</label>
        <div class="layui-input-inline">
            <input type="text" name="classesAve" lay-verify="required" lay-reqText="" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">学校平均分</label>
        <div class="layui-input-inline">
            <input type="text" name="schoolAve" lay-verify="required" lay-reqText="" placeholder="" autocomplete="off" class="layui-input">
        </div>
    </div>

</form>

</body>
<script src="/layui.js" charset="utf-8"></script>
<script>
    layui.use(['table','layer','form'],function(){
        let table = layui.table;
        let layer=layui.layer;
        let form=layui.form;

        table.render({
            elem: '#testDetail1'
            ,url:'/testDetail/queryTestDetail'
            ,toolbar: "#testDetailToolbar"
            ,title: '试题信息'
            ,totalRow: true
            ,cols: [  [
                {type: 'checkbox', fixed: 'left', totalRowText: '合计行',align:'center'}
                ,{field:'id', title:'编号', width:120, fixed: 'left', unresize: true, sort: true,align:'center' }
                ,{field:'testId', title:'试卷编号', width:120, fixed: 'left', unresize: true, sort: true,align:'center' }
                ,{field:'testTime',width:200, title: '测试时间',align:'center', sort: true,align:'center'}
                ,{field:'titleNum',width:120, title: '题号',align:'center'}
                ,{field:'titleType', width:120,title: '题目类别',align:'center'}
                ,{field:'knowledge', width:200,title: '考点',align:'center'}
                ,{field:'konwdlage', width:200,title: '知识',align:'center'}
                ,{field:'lowestScore', width:200,title: '最低分',align:'center'}
                ,{field:'highestScore', width:200,title: '最高分',align:'center'}
                ,{field:'classesAve', width:200,title: '班级平均分',align:'center'}
                ,{field:'schoolAve', width:200,title: '学校平均分',align:'center'}
                ,{title:"操作",toolbar:"#testDetailBar" ,width:150,fixed:'right',align:'center'}
            ]  ]
            ,page: true
            ,response: {
                statusCode: 200 //重新规定成功的状态码为 200，table 组件默认为 0
            }
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.items //解析数据列表
                };
            }
        });

        //监听头部工具栏事件
        table.on("toolbar(testDetailInfo)",function (obj) {
            switch (obj.event) {
                case 'add':
                    openAddTest();
                    break;
                case 'deleteAll':
                    openUpdateTest();
                    break;
            }
        });

        //监听行工具栏事件
        table.on('tool(testDetailInfo)',function (obj) {

            switch (obj.event) {
                case 'update':
                    openUpdateTest(obj.data);
                    break;
                case 'delete':
                    obj.del();
                    DeleteTest(obj.data);
                    break;
            }
        });

        function openAddTest() {
            layer.open({
                type:2,//弹出层类型
                title:"添加试卷信息",
                area:['800px','600px'],
                content:'http://localhost:8080/test/TestAddTestDetail.html',
                success:function () {
                    $("#addTestDetail")[0].reset()
                }
            })
        }

        let url;//提交地址
        let mainIndex;//窗口索引
        function openUpdateTest(data) {
            mainIndex= layer.open({
                type:1,//弹出层类型
                title:"修改试卷信息",
                area:['800px','600px'],
                shade: 0,
                btn: ['提交', '重置'],
                btn1: function(index, layero){
                    let data = form.val("testDetailInfo");
                    $.post("/testDetail/modify",data,function (res) {
                        if (res.success=="true"){
                            layer.alert("修改成功！",{icon:6,time:2000})
                        }
                    });
                    layer.closeAll();
                    return true;
                },btn2: function(index, layero){
                    $("#testDetail2")[0].reset();
                    return false;
                },
                cancel: function(layero,index){
                    layer.closeAll();
                },
                content:$("#testDetail2"),
                success:function () {
                    //表单数据回显
                    form.val("testDetail2",data);
                }
            })

        }
        function DeleteTest(data) {
            layer.confirm("确定删除吗？",{icon:3,title:"提示"},function (deleteTest) {
                $.post("/testDetail/delete",{id:data.id},function (res) { // "id="+data.id
                    if (res.success=="true"){
                        layer.alert("删除成功！",{icon:6,time: 2000});
                        // layer.close(deleteStu);
                    } else{
                        layer.alert(res.msg,{icon:5,time: 2000})
                    }
                    layer.close(deleteTest);
                })
            })

        }
    });
</script>
</html>